package com.pubsys.main.client.obsoleto;


import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.pubsys.main.client.componentes.listboxreferencias.ListBoxTipoReferencia;

public class InclusaoForm extends Composite implements ClickHandler,
		ChangeHandler {

	private Grid grdPanelFilter;
	private Grid grdPanelBtn;
	private ListBoxTipoReferencia lbxTipo;
	private Grid grdPanelMaster = new Grid(3, 1);
	private VerticalPanel vPanelFormTipo = new VerticalPanel();
	private Button btnIncluir;
	private TextBox txbAutor;
	private TextBox txbTitulo;
	private TextBox txbAno;

	public InclusaoForm() {

		txbAutor = new TextBox();
		txbTitulo = new TextBox();
		txbAno = new TextBox();

		grdPanelFilter = new Grid(4, 2);

		Label lblAutor = new Label("Autor:");
		grdPanelFilter.setWidget(0, 0, lblAutor);
		grdPanelFilter.setWidget(0, 1, txbAutor);

		Label lblTitulo = new Label("Titulo:");
		grdPanelFilter.setWidget(1, 0, lblTitulo);
		grdPanelFilter.setWidget(1, 1, txbTitulo);

		Label lblAno = new Label("Ano:");
		grdPanelFilter.setWidget(2, 0, lblAno);
		grdPanelFilter.setWidget(2, 1, txbAno);

		lbxTipo = new ListBoxTipoReferencia();
		lbxTipo.addChangeHandler(this);

		Label lblTipo = new Label("Tipo:");
		grdPanelFilter.setWidget(3, 0, lblTipo);
		grdPanelFilter.setWidget(3, 1, lbxTipo);

		vPanelFormTipo.add(new HTML(
				"Escolha um tipo para mostrar outros campos..."));

		btnIncluir = new Button();
		btnIncluir.setText("Incluir");
		btnIncluir.addClickHandler(this);

		grdPanelBtn = new Grid(1, 2);
		grdPanelBtn.setWidget(0, 1, btnIncluir);

		grdPanelMaster.setWidget(0, 0, grdPanelFilter);
		grdPanelMaster.setWidget(1, 0, vPanelFormTipo);
		grdPanelMaster.setWidget(2, 0, grdPanelBtn);

		// All composites must call initWidget() in their constructors.
		initWidget(grdPanelMaster);

		// Give the overall composite a style name.
		setStyleName("InclusaoForm");

	}

	public void onClick(ClickEvent event) {
		Widget sender = (Widget) event.getSource();

		if (sender == btnIncluir) {
			// TODO: completar handler
		}
	}

	public void onChange(ChangeEvent event) {
		//Widget sender = (Widget) event.getSource();
		//TODO: testar se sender
		switch (lbxTipo.getSelectedIndex()) {
		case 1:
			grdPanelMaster.remove(vPanelFormTipo);
			vPanelFormTipo = new VerticalPanel();
			vPanelFormTipo.add(new HTML("Você selecionou Inproceedings."));
			grdPanelMaster.setWidget(1, 0, vPanelFormTipo);
			break;

		default:
			grdPanelMaster.remove(vPanelFormTipo);
			vPanelFormTipo = new VerticalPanel();
			vPanelFormTipo.add(new HTML("Completar o switch."));
			grdPanelMaster.setWidget(1, 0, vPanelFormTipo);
			break;
		}

	}

}
